<template>
    <div class="manage">
        <div class="manage-header">
            <el-button type="text" @click="dialogVisible = true">新增+</el-button>
        </div>
        <el-dialog title="新增用户" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">

            <el-form ref="form" :model="form" label-width='80px' :inline="true" :rules="rules">
                <el-form-item label="姓名" prop="name">
                    <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
                </el-form-item>
                <el-form-item label="年龄" prop="age">
                    <el-input v-model="form.age" placeholder="请输入年龄"></el-input>
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <el-select v-model="form.sex" placeholder="请选择性别">
                        <el-option label="男" value="1"></el-option>
                        <el-option label="女" value="0"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="出生日期" prop="birth">
                    <el-date-picker type="date" placeholder="选择日期" v-model="form.birth"
                        style="width: 100%;"></el-date-picker>
                </el-form-item>
                <el-form-item label="地址" prop="addr">
                    <el-input v-model="form.addr" placeholder="请输入地址"></el-input>
                </el-form-item>

            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="cancel">取 消</el-button>
                <el-button type="primary" @click="submit">确 定</el-button>
            </span>
        </el-dialog>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="date" label="日期" width="180">
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="180">
            </el-table-column>
            <el-table-column prop="address" label="地址">
            </el-table-column>
        </el-table>
    </div>
</template>
<script>


// {
//   model:'name',
//   label:'姓名',
//   type:'input'
// },
// {
//   model:'age',
//   label:'年龄',
//   type:'input'
// },
// {
//   model:'sex',
//   label:'性别',
//   type:'select',
//   opts:[
//     {
//         label:'男',
//         value:1
//     },
//     {
//         label:'女',
//         value:0
//     }
//   ]
// },
// {
//   model:'birth',
//   label:'出生日期',
//   type:'date'
// }，
// {
//   model:'addr',
//   label:'地址',
//   type:'input'
// }


export default {
    data() {
        return {
            dialogVisible: false,
            form: {
                name: '',
                age: '',
                sex: '',
                birth: '',
                addr: ''
            },
            rules: {
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' },
                    { min: 2, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
                ],
                age: [
                    { required: true, message: '请输入年龄', trigger: 'blur' }
                ],
                sex: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                birth: [
                    { required: true, message: '请选择出生日期', trigger: 'blur' }
                ],
                addr: [
                    { required: true, message: '请填写地址', trigger: 'blur' }
                ]
            },
            tableData:[]
        }

    },
    methods: {
        //提交用户表单
        submit() {
            this.$refs.form.validate((valid) => {
                console.log(valid, 'valid');
                //为true才能进行处理
                if (valid) {
                    //  console.log(this.form,'form');
                    //关闭弹窗,清空表单
                    this.$refs.form.resetFields()
                    this.dialogVisible = false
                    //在弹窗关闭时将表单数据清除

                }

            })
        },
        //弹窗关闭事件
        handleClose() {
            console.log(this.form, 'form');
            //清空表单
            this.$refs.form.resetFields()
            this.dialogVisible = false
        },
        cancel() {
            this.handleClose()
        }
    }
}
</script>